package com.itheima.project.feign;

import com.itheima.project.basic.ResponseWrap;
import com.itheima.project.core.enums.search.SearchEnum;
import com.itheima.project.exception.ProjectException;
import com.itheima.project.hystrix.SearchHystrix;
import com.itheima.project.utils.ResponseWrapBuild;
import com.itheima.project.vo.search.RequestParamVo;
import com.itheima.project.vo.search.SearchPageVo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author mrchen
 * @date 2022/4/3 15:35
 */
@FeignClient(value = "module-search-web", fallbackFactory = SearchHystrix.class)
public interface SearchFeign {
    // ==================================  文档 CRUD  ==============================================

    /**
     * @param source 文档内容
     * @return
     */
    @PostMapping("/doc/{indexName}/save")
    ResponseWrap<Boolean> saveDoc(@PathVariable("indexName") String indexName,@RequestBody Object source);
    /**
     * 根据id删除es数据
     */
    @DeleteMapping("/doc/{indexName}/{id}")
    ResponseWrap<Boolean> deleteDoc(@PathVariable("indexName") String indexName, @PathVariable("id") String id);
    /**
     * 根据id删除es数据
     */
    @GetMapping("/doc/{indexName}/{id}")
    ResponseWrap<Map> getById(@PathVariable("indexName") String indexName, @PathVariable("id") String id);
    /**
     * 批量将数据导入es中
     */
    @PostMapping("/doc/{indexName}/batch")
    ResponseWrap<Boolean> saveDocBatch(@PathVariable("indexName") String indexName, @RequestBody List<Object> list);
    /**
     * 多条件检索
     */
    @PostMapping("/doc/{indexName}/search")
    ResponseWrap<SearchPageVo<Map>> searchDoc(@PathVariable("indexName") String indexName, @RequestBody RequestParamVo paramVo);

    /**
     * 原生多条件检索
     * return: 返回结果 封装成通用VO对象
     */
    @PostMapping("/doc/{indexName}/native-search/page-result")
    ResponseWrap<SearchPageVo<Object>> searchDocPageResult(@PathVariable("indexName") String indexName,@RequestBody String searchContent);

    /**
     * 原生多条件检索
     * return: 返回结果 原生 SearchResponse对应json
     */
    @PostMapping("/doc/{indexName}/native-search/native-result")
    ResponseWrap<String> searchDocNativeResult(@PathVariable("indexName") String indexName,@RequestBody String searchContent);



    // ==================================  索引库 CRUD  ==============================================
    /**
     * 索引库是否存在
     */
    @GetMapping("/index/exist")
    public ResponseWrap<Boolean> isExistIndex(@RequestParam(value = "indexName") String indexName);
    /**
     * 创建索引库
     */
    @PutMapping("/index/{indexName}")
    ResponseWrap<Boolean> createIndex(@PathVariable(value = "indexName") String indexName, @RequestBody String source);
    /**
     * 删除索引库
     */
    @DeleteMapping("/index/{indexName}")
    ResponseWrap<Boolean> deleteIndex(@PathVariable(value = "indexName") String indexName);
}
